﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="product-list.aspx.cs" Inherits="VQWEB.administrator.products.product_list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
<div class="table-responsive">       
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
  <script type="text/javascript">
      ShowToolBar("add");
      var url_ashx = "/admin/product/handler";
      var url_list = '<%=ResolveUrl("~/administrator/templates/list.tpl") %>';
      $(document).ready(function () {
          $.get(url_ashx, { list_product: "list_product" }, function (data) {
              list(data);
          });
      });

      $(document).on("click", "#btnAdd", function () {
          window.location = "/admin/product/add";
      });

      $(document).on("click", "#btnEdit", function () {
          var Id = $("input[name='chkItem']:checked").first().attr("value");
          if (Id != undefined)
              window.location = "/admin/product/edit/" + Id;
      });
      //LockUnLock
      $(document).on("click", "#btnLockUnlock", function () {
          var array = InputChecked();
          if (array.length > 0) {
              $.post(url_ashx, { lockunlock_product: JSON.stringify(array) }, function (data) {
                  list(data);
              });
          }
      });
      //Delete
      $(document).on("click", "#btnDelete", function (e) {
          var array = InputChecked();
          if (array.length > 0) {
              if (confirm("Bạn muốn xóa bản ghi không ???")) {
                  $.post(url_ashx, { delete_product: JSON.stringify(array) }, function (data) {
                      list(data);
                  });
              }
          }

      });

      //List
      function list(data) {
          var plusData = $.parseJSON(data);
          var columns = ["STT", "<input name='chkAll' value='' type='checkbox'>", "Title", "hit", "date", "Active"];
          var rows = new Array();
          $.each(plusData, function (i, obj) {
              var row = [];
              var active = (obj.active) ? "Kích hoạt" : "Chưa kích hoạt";
              var url = "<a href=/admin/product/view/" + obj.id + ">" + obj.title + "</a>";
              var checkbox = "<input name='chkItem' type='checkbox'  value=" + obj.id + ">";
              row.push(i + 1);
              row.push(checkbox);
              row.push(url);
              row.push(obj.hit);
              row.push(obj.date);
              row.push(active);
              rows.push(row);
          });
          $('div.table-responsive').empty();
          $.jqoteload(url_list, function (templates) {
              $('div.table-responsive').jqoteapp(templates.list_tpl, { columns: columns, rows: rows });
          });
      }
    </script>
</asp:Content>
